package atm;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class SavePanel extends JPanel implements ActionListener {
    private ATM atm;
    private JButton sureBtn;
    private JButton clearBtn;
    private Icon sureImg = Util.getImageIcon("/images/buttonSure.jpg");
    private Icon clearImg = Util.getImageIcon("/images/buttonClear.jpg");
    private JTextField cunkuan=new JTextField();

    public SavePanel(ATM atm) {
        this.atm = atm;
        this.setLayout(null);
        this.setOpaque(false);

        JLabel cun=new JLabel("请输入存款金额");
        cun.setBounds(400, 220, 90, 20);
        this.add(cun);

        cunkuan.setBounds(510, 220, 90, 20);
        this.add(cunkuan);


        sureBtn = new JButton(sureImg);
        sureBtn.setBounds(10, 40, 140, 50);
        this.add(sureBtn);
        sureBtn.addActionListener(this);

        clearBtn = new JButton(clearImg);
        clearBtn.setBounds(10, 100, 140, 50);
        this.add(clearBtn);
        clearBtn.addActionListener(this);

    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == sureBtn) {
            JOptionPane.showMessageDialog(this,"存款成功，本次存款金额为："+cunkuan.getText());
            atm.getUsers().get(atm.getA()).setMoney(Double.valueOf(cunkuan.getText())+atm.getUsers().get(atm.getA()).getMoney() );
            atm.switchPanel("menu");
        } else if (e.getSource() == clearBtn) {
            atm.switchPanel("menu");
        }
    }
}
